//
//  ZQWelcomeController.swift
//  ZQWeibo
//
//  Created by summer的Dad on 16/11/16.
//  Copyright © 2016年 summer的Dad. All rights reserved.
//

import UIKit
import SDWebImage
private let margin : CGFloat = 120
class ZQWelcomeController: UIViewController {
    
    //执行动画要在didappear
    
    override func viewDidAppear(_ animated: Bool) {
        
        animation()
        
    }
    

    override func viewDidLoad() {
        super.viewDidLoad()

        
        setupUI()
        
    }
    
    //设置动画
    func animation () {
        
    let offsetY = -(UIScreen.main.bounds.height - margin - iconImage.bounds.height)
        
        
     UIView.animate(withDuration: 1.5, delay: 0, usingSpringWithDamping: 0.8, initialSpringVelocity: 7, options: [], animations: {
        self.iconImage.snp.updateConstraints({ (make) in
            make.bottom.equalTo(self.view).offset(offsetY)
        })
        self.view.layoutIfNeeded()
        
     }, completion:{ (finishend) -> () in
        
        UIView.animate(withDuration: 0.5, animations: {
            
            self.welcomeLable.alpha = 1
            
        }, completion: { (_) -> () in
         
//            
//      UIApplication.shared.keyWindow?.rootViewController = ZQTabBarController()
        //发出通知
        NotificationCenter.default.post(name: NSNotification.Name(kRootViewController), object: nil)
            
            
            
        })

        })
    }
    //搭建界面
   private func setupUI() {
    
    self.view.backgroundColor = #colorLiteral(red: 1, green: 1, blue: 1, alpha: 1)
    //头像
    self.view.addSubview(iconImage)
    //提示文字
    self.view.addSubview(welcomeLable)
    
    //约束
    
    iconImage.snp.makeConstraints { (make) in
        
        make.centerX.equalTo(self.view)
        make.bottom.equalTo(self.view).offset(-margin)
         make.size.equalTo(CGSize(width: 85, height: 85))
        
       
    }
    welcomeLable.snp.makeConstraints { (make) in
        make.top.equalTo(iconImage.snp.bottom).offset(20)
        make.centerX.equalTo(iconImage.snp.centerX)
    }
    
    welcomeLable.alpha = 0
    
    //设置圆角
      iconImage.layer.cornerRadius = 85 * 0.5
    
    iconImage.layer.masksToBounds = iconImage.layer.cornerRadius > 0
    
  
    //下载
    

    iconImage.sd_setImage(with: ZQUserAccountViewModel.shared.headURL)
 
//    print( ZQUserAccountViewModel.shared.headURL)
    }
    
    private lazy var iconImage : UIImageView = UIImageView(image:#imageLiteral(resourceName: "avatar_default"))
    
    private lazy var welcomeLable : UILabel = UILabel(title: "欢迎归来", fontSize: 16, textColor: #colorLiteral(red: 0.2549019754, green: 0.2745098174, blue: 0.3019607961, alpha: 1))
    
    
    
    
    

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
    

    /*
    // MARK: - Navigation

    // In a storyboard-based application, you will often want to do a little preparation before navigation
    override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
        // Get the new view controller using segue.destinationViewController.
        // Pass the selected object to the new view controller.
    }
    */

}
